/*
 * @Date         : 2022-06-07 18:56:12
 * @LastEditors  : zu1662
 * @LastEditTime : 2024-05-24 14:33:20
 * @Description  : Swagger配置项
 *
 * Copyright © 2022 by zu1662, All Rights Reserved.
 */
import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function setupSwagger(app: INestApplication): Promise<void> {
  const descriptionStr = `Walle Open Api Document`;

  const configService = app.get(ConfigService);
  const name: string = configService.get<string>('app.name');
  const version: string = configService.get<string>('app.version');
  const documentBuilder = new DocumentBuilder()
    .setTitle(`${name} API`)
    .setDescription(descriptionStr);

  if (version) {
    documentBuilder.setVersion(version);
  }

  const document = SwaggerModule.createDocument(app, documentBuilder.build());
  SwaggerModule.setup('documentation', app, document);
}

export default setupSwagger;
